<?php
/* SVN FILE: $Id: fw24h_app_controller.php 56 2009-11-04 02:06:51Z phamshantuyet@gmail.com $ */
/**
*
* @author $Author: phamshantuyet@gmail.com $
* @version $Revision: 56 $
* @lastrevision $Date: 2009-11-04 02:06:51 +0000 (Wed, 04 Nov 2009) $
* @modifiedby $LastChangedBy: phamshantuyet@gmail.com $
* @lastmodified $LastChangedDate: 2009-11-04 02:06:51 +0000 (Wed, 04 Nov 2009) $
* @filesource $URL: http://ladybirdphp.googlecode.com/svn/trunk/website/ocm/app/fw24h_app_controller.php $
*/


fw24h_useVendor( '_funcs');

class FW24H_AppController extends FW24H_Controller {

	var $useModel = array( 'User', 'Menu');

	var $useComponent = array( 'Email');
	var $useHelpers = array( 'HtmlHelper', 'UrlHelper');

	var $currentMenu = array();
	
	function beforeFilter(){


		//$this->checkLogin();

		// Listing menu
		if($arrMenu = $this->Menu->categoryArray()){
			$this->setParam('arrMenu', $arrMenu);
		}

		// lay menu Id hien tai tu controllerName & actionName
		$currentMenu = $this->Menu->getMenuFromLink( $this->controllerName.'/'.$this->actionName);
		$this->currentMenu = $currentMenu[0];
	}

	function checkLogin() {
		$this->User->checkCookie();
		
		if( !isset( $_SESSION['OCM_LOGIN']) && !isset( $_SESSION['OCM_UID']) && !isset( $_SESSION['OCM_UNAME'])){
			$this->redirect( BASE_URL.'user/login');
		}
		return true;
	}

	function checkPermission( $perm = 'read', $menu = '') {
		$menu_id = $this->currentMenu['menu_id'];
		if( $menu != '') {
			if( $Menu = $this->Menu->getMenuFromLink( $menu)) {
				$menu_id = $Menu[0]['menu_id'];
			}
		}
		if( !$this->User->getPerm( $menu_id, $_SESSION['OCM_UID'], $perm)) {
			$this->redirect( BASE_URL.'user/access_deny');
		}
	}
}

